package com.ffms.servlet;

import com.ffms.entity.FamilyMember;
import com.ffms.entity.Shouru;
import com.ffms.entity.ZhiChu;
import com.ffms.service.AdminService;
import com.ffms.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/AllZhiChuServlet")
public class AllZhiChuServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取用户请求数据
        Object user = request.getSession().getAttribute("user");
        AdminService adminService = new AdminServiceImpl();
        List<ZhiChu> zhuchuList;
        if (user instanceof FamilyMember) {
            FamilyMember familyMember = (FamilyMember) user;
            zhuchuList = adminService.findzhihchuByMid(familyMember.getSid());
        } else {
            zhuchuList =adminService.findzhihchu();
        }
        //2.调用业务层调取成员信息

        //3.跳转到显示成员页面
        request.setAttribute("zhuchuList", zhuchuList);
        request.getRequestDispatcher("admin/allZhichuList.jsp").forward(request, response);
    }
}
